var loginDepartment;

//登陆成功后跳转到其他页面
function redirectPage()
{
	if(loginDepartment=='leader'){
		location.href="leaderAction";  //领导入口
	}else if(loginDepartment=='colleges'){
		location.href="registerAction";  //二级学院
	}else if(loginDepartment=='finance'){
		location.href="financeAction";  //财务处
	}else if(loginDepartment=='enrollment'){
		location.href="enrollmentAction"; //招生处 
	}else if(loginDepartment=='logistics'){
		location.href="logisticsAction";  //后勤部
	}else if(loginDepartment=='declare'){
		location.href="declareAction";  //宣保处
	}else if(loginDepartment=='student'){
		location.href="studentOfficeAction";  //学生处
	}
}

function login(){
	//loginForm
	//校验用户名和密码
	if($("#userName").val()==""){
		$("#userNameError").html("用户名不能为空");
		$("#userName").bind("keyup",function(){
			if($("#userName").val()!=""){
				$("#userNameError").html("");
			}
		})
	}else if($("#password").val()==""){
		$("#passwordError").html("密码不能为空");
		$("#password").bind("keyup",function(){
			if($("#password").val()!=""){
				$("#passwordError").html("");
			}
		})
	}else if($("#validateCode").val()==""){
		$("#validateCodeError").html("验证码不能为空<br>");
		$("#validateCode").bind("keyup",function(){
			if($("#validateCode").val()!=""){
				$("#validateCodeError").html("");
			}
		})
	}else{//输入全部符合条件
		var password=$("#password").val();
		var userName=$("#userName").val();
		var validateCode=$("#validateCode").val();
		param={};
		param.date=new Date();
		param.password=password;
		param.userName=userName;
		param.department=loginDepartment
		param.validateCode=validateCode;
		if(loginDepartment=="colleges"){//选中二级学院时还要把所选中的学院id传过去
			param.collegeId=$("#collegesList").val();
			param.admin=$("#Admin").attr("checked");
			//param.admin=true;
			//alert($("#Admin").attr("checked"))
			$.cookie("college",$("#collegesList").val(),{expires: 2})
		}

		$.post("json/loginAction",param,function(data){
			
			if(data.result=="success"){
				//alert("登陆成功");
				redirectPage();
			}else{
				alert(data.result)
				reloadValidate();//更换验证码
				$("#validateCode").val("")
			}
		})
	}
	$.cookie("department",loginDepartment,{expires: 2})
	//addCookie(loginDepartment);
}



var pz=0;
//var op=1;
function forward(text,text1,department){

	$("#BgDiv").css("display","none");
	$("#DialogDiv").css("display","none");
	$('#title').html(text);
	$('#title3').html(text1);
	$('#l').html(text);
	if(text=="二级学院"){
		pz=1;
		$('#chooseCollege').show();
		$('#chooseRole').show();
		$('.table').css('margin-top','-30px');							//	如果是二级学校，即改变表格位置
		$('.table').css('margin-left','0px');
	}else{
		pz=0;
		$('#chooseRole').hide();
		$('#chooseCollege').hide();
		$('.table').css('margin-top','0px');
		$('.table').css('margin-left','0px');
	}
	loginDepartment=department;
}

$(document).ready(function()
{
	var leadership="方便学校的领导实时查看各学院的新生报到情况和缴费情况。";
	var indexstr="各学院的前台管理员的登录，登录后各学院的前台管理员可以对前来报到的新生进行注册。";
	var finance="财务部门登录，登录后财务部门可以查看学生的缴费和欠费情况，也可以导入或更行学生的的缴费信息。";
	var enrollment="招就部门登录，登录后，可以查看各学院的报道率，以及查询学生的报道情况";
	var student="登录后，可以查看各学院的报道率，以及查询学生的报道情况";
	var logistics="后勤部门登录，登录后可以查看学校的宿舍使用情况，可以对宿舍进行 禁用、分配备用宿舍、重新分配宿舍等功能。";
	var declare="登记学生是否转户口，也可以查看操作过的历史记录。"
	$(".btnClose").click(function()
	{
		$("#BgDiv").css("display","none");
		$("#DialogDiv").css("display","none");
	});
	$("#chooseDepartment").click(function()
	{
	
		var str;
		str='<table width="330" border="0" cellspacing="10" cellpadding="0" id="showtable">'
		str=str+'<tr>';
		str=str+'<td align="center"><a href="javascript:void(0)" onclick="forward(\'领导入口\',\''+leadership+'\',\'leader\')">领导入口</a></td>';
		str=str+'<td align="center"><a href="javascript:void(0)" onclick="forward(\'二级学院\',\''+indexstr+'\',\'colleges\')">二级学院</a></td>';
		str=str+'<td align="center"><a href="javascript:void(0)" onclick="forward(\'财务处\',\''+finance+'\',\'finance\')">财务处</a></td>';
		str=str+'</tr><tr>';
		str=str+'<td align="center"><a href="javascript:void(0)" onclick="forward(\'招就处\',\''+enrollment+'\',\'enrollment\')">招就处</a></td>';
		str=str+'<td align="center"><a href="javascript:void(0)" onclick="forward(\'学生处\',\''+student+'\',\'student\')">学生处</a></td>';
		str=str+'<td align="center"><a href="javascript:void(0)" onclick="forward(\'后勤部\',\''+logistics+'\',\'logistics\')">后勤部</a></td>';
		str=str+'</tr><tr>';
		str=str+'<td align="center"><a href="javascript:void(0)" onclick="forward(\'宣保处\',\''+declare+'\',\'declare\')">宣保处</a></td>' +
				'<td align="center"><a href="javascript:location.href=\'admin/login.jsp\'">后台管理员 </a></td><td>&nbsp;</td>';
		str=str+'</tr>';
		str=str+'</table>';
		$(".form").html(str);
		$("#BgDiv").css({ display:"block",height:$(document).height()});
		var yscroll=document.documentElement.scrollTop;
		$("#DialogDiv").css("top","100px");
		$("#DialogDiv").css("display","block");
		document.documentElement.scrollTop=0;
	});
	$('#login a').bind('mouseover',function(){
		$('.right').css('background-image','url("images/login_button1.jpg")');
	});
	$('#login a').bind('mouseout',function(){
		$('.right').css('background-image','url("images/login_button.jpg")');
	});
	$('#BgDiv').bgiframe();
	var dp=$.cookie("department")
	if(dp=='leader'){
		forward('领导入口',leadership,'leader');
	}else if(dp=='finance'){
		forward('财务处',finance,'finance');
	}else if(dp=='enrollment'){
		forward('招就处',enrollment,'enrollment');
	}else if(dp=='logistics'){
		forward('后勤部',logistics,'logistics');
	}else if(dp=='declare'){
		forward('宣保处',declare,'declare');
	}else if(dp=='student'){
		forward('学生处',student,'student');
	}else{
		forward('二级学院',indexstr,'colleges');//如果系统是第一次登陆或cookie过期时默认二级学院
		var college=$.cookie("college");
		
		setTimeout(function(){
			if(college){
				$("#collegesList").val(college)
			}
		},0.001)
	}
	
});


/*

function addCookie(str){

	document.cookie="department="+str;
}
function getCookie(cookie_name)
{

	var allcookies = document.cookie;
	var cookie_pos = allcookies.indexOf(cookie_name);
	if (cookie_pos != -1){
		cookie_pos += cookie_name.length + 1;
		var cookie_end = allcookies.indexOf(";", cookie_pos);
		if (cookie_end == -1){
			cookie_end = allcookies.length;
		}
		var value = unescape(allcookies.substring(cookie_pos, cookie_end));
	}
	
	return value;
}*/

